function factorial(n) {
    if (n === 1) { return 1 }
    return n * factorial(n - 1)
}

onmessage = function(e){
    const {value} = e.data
    const res = factorial(value)
    let time = new Date().getTime()
    while(new Date().getTime() < time + 5000){
    }
    postMessage({ res })
    this.self.close()
}